package com.sanhuo.idms.dao;

import com.sanhuo.idms.bo.DormHighSearchBO;
import com.sanhuo.idms.dao.provider.DormProvider;
import com.sanhuo.idms.entity.Dorm;
import com.sanhuo.idms.vo.DormDetailVO;
import com.sanhuo.idms.vo.DormPageVO;
import com.sanhuo.triild.Basic.BaseMapper;
import com.sanhuo.triild.annotation.Mapper;
import com.sanhuo.triild.annotation.Select;
import com.sanhuo.triild.annotation.SelectProvider;
import com.sanhuo.triild.page.Page;
import com.sanhuo.triild.page.PageSearch;

import java.util.List;


@Mapper
public interface DormMapper extends BaseMapper<Dorm> {

//    @Select("select * from dorm where id = #{id}")
//    Dorm findById(String id);

    @Select("select * from dorm  where tungId = #{tungId} and roomId = #{roomId}")
    Dorm findByTungAndRoom(String tungId, String roomId);

    @SelectProvider(type = DormProvider.class, method = "listAll")
    Page<DormPageVO> listAll(DormHighSearchBO bo, PageSearch findAllDetail);

    //    @InsertProvider(type = DormProvider.class, method = "insert")
//    void insert(Dorm dorm);
//
//    @Select("select * from dorm")
//    List<Dorm> findAll();
    @Select("select d.id ,t.num tungNum,r.num roomNum,e.updateTime,total,consume from dorm d,tung t,room r,dorm_electric e where  d.id = e.dormId" +
            "   and d.tungId = t.id and d.roomId = r.id and d.id = #{id}")
    DormDetailVO detail(String id);

    @Select("select dorm.* from dorm join tung join room" +
            " on dorm.tungId = tung.id and dorm.roomId = room.id " +
            "where tung.num = #{tungNum} and room.num = #{roomNum}")
    Dorm findByNum(int tungNum, int roomNum);


}
